#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int N=15;

int n,a[N];
bool b[N];

void dfs(int i)
{
	if (i==n+1) 
	{
		for (int j=1;j<=n;j++) printf("%d ",a[j]);puts("");
		return ;
	}
	for (int j=1;j<=n;j++) if (!b[j]) 
	{
		b[j]=true;
		a[i]=j;
		dfs(i+1);
		b[j]=false;
	}
}
int main()
{
	scanf("%d",&n);
	dfs(1);
	return 0;
}

